require "test/unit"

require 'test_helper'

class TestAddRecords < Test::Unit::TestCase

  # Called before every test method runs. Can be used
  # to set up fixture information.
  def setup
    # Do nothing
  end

  # Called after every test method runs. Can be used to tear
  # down fixture information.

  def teardown
    # Do nothing
  end

  #Test that the database has nothing.
  def test_db_add_record
    #add a row
    product = Product.new
    product.description = "basic test, nothing special"
    save = product.save

    assert(save, "It failed")

    #find it again
    allrecords = Product.find(product.id)

    #delete that row
    allrecords.destroy

    #make sure that row was deleted
    allrecords = Product.find(:all)
    assert_equal(0, allrecords.length )
  end

  def test_db_add_record_with_optional_creation_block
    product = Product.new do |prod|
      prod.description = "We added with a block!"
    end
    save = product.save

    assert(save, "It failed")

    record = Product.find(product.id)
    record.destroy

    #make sure that row was deleted
    allrecords = Product.find(:all)
    assert_equal(0, allrecords.length )
  end

  def test_db_add_records_with_create_method
    product = Product.create( :description => "Hey I'm added with a hash.", :name => "epic win record")
    save = product.save

    assert(save, "It failed")

    record = Product.find(product.id)
    record.destroy

    #make sure that row was deleted
    allrecords = Product.find(:all)
    assert_equal(0, allrecords.length )
    
  end



end